package itd.newbee.mall.newbeemall.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import itd.newbee.mall.newbeemall.Dao.AdminMapper;
import itd.newbee.mall.newbeemall.entity.Admin;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.util.*;

/**
 * @author Administrator
 * @version 1.0
 * @description: TODO
 * @date 2025/3/7 19:58
 */
@RestController
@Tag(name="管理员接口")
public class TestSwaggerController {


    private final AdminMapper adminMapper;

    public TestSwaggerController(AdminMapper adminMapper) {
        this.adminMapper = adminMapper;
    }


    @Operation(summary="插入一条管理员信息",description = "根据Admin对象插入")
    @PostMapping("/Admins/insertOne")
    public Integer insertOne(@RequestBody
                                 @Parameter(description = "管理员信息对象", required = true)
                                 Admin admin){
       return adminMapper.insertOne(admin);

    }
    static Map<Integer, Admin> adminMap = Collections.synchronizedMap(new HashMap<Integer, Admin>());

    static{
        Admin admin = new Admin();
        admin.setId(8);
        admin.setName("zwy8");
        admin.setPassword("88888888");
        Admin admin1 = new Admin();
        admin1.setId(9);
        admin1.setName("zwy9");
        admin1.setPassword("99999999");
        adminMap.put(8,admin);
        adminMap.put(9,admin1);
    }
    @Operation(summary = "获取管理员信息",description = "静态信息")
    @GetMapping("/Admins")
    public List<Admin> getAdminList(){
        List<Admin> admins = new ArrayList<Admin>(adminMap.values());
        return admins;
    }
}
